#include "stdafx.hpp"
#include "ColligereLanguageSelectionDlg.hpp"
#include "ColligereApp.hpp"

col::LanguageSelectionDlg::LanguageSelectionDlg ( wxWindow *pParent )
{
	wxXmlResource::Get()->LoadDialog ( this, pParent, "ID_Dialog_Language" );

	wxBitmapComboBox *langs = XRCCTRL ( *this, "ID_BitmapComboBox_Language",
		wxBitmapComboBox );

	wxInt32 lang_sel = -1;

	foreach ( Language l, wxGetApp().GetAvailableLanguages() )
	{
		if ( l.GetLanguage() == wxLANGUAGE_ENGLISH )
		{
			lang_sel = langs->Append ( l.GetDisplayString(), l.GetFlag(), 
				new LanguageClientData ( l.GetLanguage() ) );
		}
		else
		{
			langs->Append ( l.GetDisplayString(), l.GetFlag(), 
				new LanguageClientData ( l.GetLanguage() ) );
		}
	}
	wxASSERT ( lang_sel != -1 );
	langs->SetSelection ( lang_sel );
}

wxLanguage col::LanguageSelectionDlg::GetLanguage() const
{
	const wxBitmapComboBox *langs = XRCCTRL ( *this, "ID_BitmapComboBox_Language",
		wxBitmapComboBox );

	wxASSERT ( langs->GetSelection() != wxNOT_FOUND );

	const LanguageClientData *lang_data = dynamic_cast < const LanguageClientData * > 
		( langs->GetClientObject ( langs->GetSelection() ) );
	wxASSERT ( lang_data );

	return lang_data->GetLanguage();
}